<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            height: 5000px;
        }
        #btn{
            position: fixed;
            right: 0;top: 500px;
            display: none;
        }
        #box{
            width: 100%;
            height: 100px;
            background: #000;
            position: fixed;
            top: 0;
            display: none;
            line-height: 100px;
            text-align: center;
        }
        #box input{
            width: 40%;
            height: 30px;
        }
        #box1{
            width: 100%;
            height: 200px;
            text-align: center;
            line-height: 200px;
            background: #ccc;
        }
        #box2{
            width: 100%;
            height: 200px;
            text-align: center;
            line-height: 200px;
            background: red;
        }
    </style>
</head>
<body>
    <div id="box">
        <input type="text" value="搜索">
    </div>
    <div id="box1">内容内容内容内容内容内容内容内容内容</div>
    <div id="box2">内容内容内容内容内容内容内容</div>
    <button id="btn">回到顶部</button>
</body>
<script>
    var judge = true;
    window.onscroll = function(){
        if(scrollY >= 1000){
            if(judge == false){
                return
            }
            var Height = 0;
            var t = setInterval(function(){
                Height += 10;
                if(Height >= 100){
                    Height = 100;
                    clearInterval(t);
                }
                box.style.height = Height + 'px';
            },10)
            btn.style.display = 'block'
            box.style.display = 'block'
            judge = false;
        }else{
            btn.style.display = 'none'
            box.style.display = 'none'
            judge = true;
        }
    }
    var timer;
    btn.onclick = function(){
        clearInterval(timer)
        timer = setInterval(function(){
            if(scrollY <= 0){
                clearInterval(timer)
            }
            scrollTo({top:scrollY - 100})
        },10)
    }
</script>
</html>